//
//  LCStatusBarOverlay.m
//  安好
//
//  Created by lianchuang on 14/12/1.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "LCStatusBarOverlay.h"
#import "YXJSON.h"
@implementation LCStatusBarOverlay
{
    UIView *view;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (LCStatusBarOverlay *)shared {
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}
- (id)init
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        self.windowLevel = UIWindowLevelStatusBar + 1;
        self.backgroundColor=[UIColor clearColor];
        self.frame = [UIApplication sharedApplication].statusBarFrame;
        self.dic=[[NSDictionary alloc]init];
        
        view=[[UIView alloc] initWithFrame:CGRectMake(kScreenWidth, 0, 160, 20)];
        view.layer.cornerRadius=9;
        view.backgroundColor=[ClassMethodsViewController colorWithHexString:@"#03b9f9"];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapflag)];
        [view addGestureRecognizer:tap];
        view.layer.masksToBounds=YES;
        [self addSubview:view];
        
        self.messageLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 20)];
//        self.messageLabel.text=@"新消息";
        self.messageLabel.backgroundColor=[UIColor clearColor];
        self.messageLabel.textColor=[UIColor whiteColor];
        self.messageLabel.textAlignment=NSTextAlignmentCenter;
        self.messageLabel.font=[UIFont systemFontOfSize:13];
        [view addSubview:self.messageLabel];
        [self makeKeyAndVisible];
    }
    return self;
}
- (void)analysisIMmessage:(id)message
{
    self.dic=[YXJSON dictionaryOrArrayWithJSONSString:message];
    self.messageLabel.text=[self.dic objectForKey:@"username"];
}
/**
 *  展示气泡
 */
- (void)showMessageLabel
{
    [UIView animateWithDuration:0.3 animations:^{
        view.frame=CGRectMake(kScreenWidth-100, 0,120, 20);
    } completion:^(BOOL finished) {
    }];
}
/**
 *  隐藏气泡
 */
- (void)hidenMessageLabel
{
    [UIView animateWithDuration:0.3 animations:^{
        view.frame=CGRectMake(kScreenWidth, 0, self.messageLabel.width, 20);
    } completion:^(BOOL finished) {
        
    }];
}
- (void)tapflag
{
    
    [self hidenMessageLabel];
    if (self.statusDelegate&&[self.statusDelegate respondsToSelector:@selector(skipToChat:)]) {
        [self.statusDelegate skipToChat:self.dic];
    }
}
@end
